package com.lemontree.spring.service;

import com.lemontree.spring.model.User;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * @Author: YLBG-YCY-1325
 * @Description:
 * @Date: 2017/9/29
 */
@Service("userService")
public class UserService {

    @Cacheable(cacheNames ="user", condition = "#obj!=null && #obj.age<12")
    public User getUserById(User obj) {
        System.out.println(" getUser...");
        return getFromDb();
    }

    private User getFromDb() {
        System.out.println(" user from db");
        User user = new User();
        user.setUserName("miss");
        user.setAge(11);
        return user;
    }
}
